require "common/Define"
require "framework/BaseController"
require "FairyGUI"

HeadBarMain = BaseController:New({mControllerName = "HeadBarMain"});

function HeadBarMain:Main()
	-- body
	HeadBarMain:Awake();
end

function HeadBarMain:Awake()
	Application.targetFrameRate = 60;
	Stage.inst.onKeyDown:Add(self.OnKeyDown);

	-- load npc
	local origin = Resources.Load("Role/npc-with-hud");
	local npc1 = GameObject.Instantiate( origin );
	npc1.transform.position = Vector3(0, 0 ,0);
	local npc2 = GameObject.Instantiate( origin );
	npc2.transform.position = Vector3(4, 0 ,0);

	-- set value
	local headBar = npc1.transform:Find("HeadBar");
	local panel = headBar:GetComponent("FairyGUI.UIPanel");
	print(panel);
	panel.ui:GetChild("name").text = "Long [color=#FFFFFF]Long[/color][img]ui://HeadBar/cool[/img] Name";
	panel.ui:GetChild("blood").asProgress.value = 75;
	panel.ui:GetChild("sign").asLoader.url = "ui://HeadBar/task";

	panel = npc2.transform:Find("HeadBar"):GetComponent("FairyGUI.UIPanel");
	panel.ui:GetChild("name").text = "Man2";
	panel.ui:GetChild("blood").asProgress.value = 25;
	panel.ui:GetChild("sign").asLoader.url = "ui://HeadBar/fighting";
end	

function HeadBarMain:OnKeyDown(context)
 	-- body
 	if (context.inputEvent.keyCode == KeyCode.Escape) then
		print "Exit Game!"
		Application.Quit();
	end
end

function HeadBarMain:InitView()

end	